package com.meta.act.app.domain.system;

import com.meta.framework.act.entity.SysUser;
import com.meta.framework.common.utils.SecurityUtils;
import org.springframework.util.Assert;

import java.util.Optional;

/**
 * java类简单作用描述
 *
 * @Title:
 * @Package: com.meta.act.app.domain.system.
 * @Author: M.simple
 * @Remark: The modified content
 * @CreateDate: 2020/11/25 2:38 下午
 * @Version: v2.0
 */
public class SysUserDo extends SysUser {

	public static SysUserDo ofAdmin(String password, String telephone, String nickName, Long tenantId, Long deptId, Long roleId){

		Assert.notNull(password, "默认密码不为空");

		nickName = Optional.ofNullable(nickName).orElse(telephone);
		SysUserDo sysUserDo = new SysUserDo();
		sysUserDo.setUserName(nickName);
		sysUserDo.setNickName(nickName);
		sysUserDo.setPassword(SecurityUtils.encryptPassword(password));
		sysUserDo.setPhonenumber(telephone);
		sysUserDo.setTenantId(tenantId);
		sysUserDo.setCreateBy(SecurityUtils.getUserId());

		sysUserDo.setDeptId(deptId);
		Long[] roles = new Long[1];
		roles[0] = roleId;
		sysUserDo.setRoleIds(roles);

		return sysUserDo;
	}


	public static SysUserDo ofConvertSysUser(SysUser user, SysUser existUser) {

		SysUserDo returnSysUser = existUser.transform(SysUserDo.class);
		
		returnSysUser.setTenantId(user.getTenantId());
		returnSysUser.setNickName(user.getNickName());
		returnSysUser.setRoleIds(user.getRoleIds());
		returnSysUser.setDeptId(user.getDeptId());
		returnSysUser.setUserType(user.getUserType());
		returnSysUser.setSex(user.getSex());
		returnSysUser.setRemark(user.getRemark());

		return returnSysUser;
	}
}
